package com.sense.kukoo.biz_media.adapter.provider

import android.widget.ImageView
import android.widget.TextView
import com.sense.kukoo.biz_media.R
import com.sense.kukoo.biz_media.adapter.MediaListDetailAdapter
import com.sense.kukoo.common.repo.bean.BookDetailsBean
import com.sense.kukoo.common.repo.bean.MediaListDetailItemBean
import com.sense.kukoo.common.utils.ApplicationContext
import com.sense.kukoo.common.wiget.adapter.provider.MultiItemProvider
import com.sense.kukoo.common.wiget.adapter.viewholder.BaseViewHolder

class MediaListTitleProvider(
    val listener: MediaListDetailAdapter.MediaListListener,
): MultiItemProvider<MediaListDetailItemBean>() {

    override fun getItemType(): Int = MediaListDetailItemBean.TYPE_MEDIA_LIST_TITLE

    override fun getItemLayoutId(): Int = R.layout.biz_media_item_media_list_title

    override fun onBindViewHolder(viewHolder: BaseViewHolder, bean: MediaListDetailItemBean) {
        val data: BookDetailsBean = bean.bean!!
        //
        val chapterTotal = data.chapterTotal
        val text = ApplicationContext.getString(com.sense.kukoo.common_i18n.R.string.media_controler_episodes, chapterTotal)
        //
        val tv_media_list_title = viewHolder.getView(R.id.tv_media_list_title) as TextView
        tv_media_list_title.setText(text)
        //
        val isSort = data.localAsc == 1
        val iv_btn_media_list_sort = viewHolder.getView(R.id.iv_btn_media_list_sort) as ImageView
        if (isSort) {
            iv_btn_media_list_sort.setImageResource(R.drawable.biz_media_icon_media_sort_down)
        }else{
            iv_btn_media_list_sort.setImageResource(R.drawable.biz_media_icon_media_sort_up)
        }
        iv_btn_media_list_sort.setOnClickListener {
            listener.onBtnSortClick(bean)
        }
    }
}